#include "Fraction.h"
#include <ECS/Containers/TableArray.h>
#include <map>

class FractionTable
{
public:
	static FractionTable* getInstance()
	{
		if (_instance == nullptr)
			_instance = new FractionTable();
	}
protected:
	ECS::TableArray<int> _relationsTable;
	static FractionTable* _instance;
};

std::map<std::pair<int, int>, Relation> _relationTable;

Fraction::Fraction(int Id) : _id(Id)
{

}

Fraction* Fraction::get( int id )
{
	return new Fraction(id);
}

const Relation& Fraction::getRelationTo( Fraction* other ) const
{
	auto it = _relationTable.find(std::make_pair(_id, other->_id));

	if (it != _relationTable.end())
		return it->second;
	else
	{
		Relation r;
		_relationTable[std::make_pair(_id, other->_id)] = r;
		return _relationTable[std::make_pair(_id, other->_id)];
	}
}

void Fraction::setRelations( Fraction* other, const Relation& relation )
{
	_relationTable[std::make_pair(_id, other->_id)] = relation;
}
